/*
 * TypeAst.cpp
 *
 *  Created on: 5 Nov 2010
 *      Author: kn308
 */

#include <sstream>
#include <llvm/TypeSymbolTable.h>

#include "TypeAst.h"
#include "ErrorAst.h"
#include "../Codegen.h"



namespace MAlice
{

TypeAst::TypeAst(const string& name) :
	mName(name)
{
}

TypeAst::~TypeAst()
{
}

const llvm::Type* TypeAst::type()
{
	Codegen* g  = Codegen::get();
	Module* mod = g->getModule();
	TypeSymbolTable& syms = mod->getTypeSymbolTable();
	TypeSymbolTable::const_iterator i = syms.find(StringRef(mName));
	if (i == syms.end())
	{
		stringstream ss;
		ss << '\'' << mName << '\'' << " is not a defined type";
		throw runtime_error(ss.str());
	}
	else
	{
		return i->second;
	}
}

llvm::Value* TypeAst::generate()
{
	return NULL;
}

}
